home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Src / HardwareContext-sparc.h < prev    next >
C/C++ Source or Header  |  1990-07-09  |  3KB  |  131 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. // 
  3. // Copyright (C) 1988 University of Illinois, Urbana, Illinois
  4. // Copyright (C) 1989 University of Colorado, Boulder, Colorado
  5. // Copyright (C) 1990 University of Colorado, Boulder, Colorado
  6. //
  7. // written by Dirk Grunwald (grunwald@foobar.colorado.edu)
  8. //
  9. #ifndef    HardwareContext_h
  10. #define    HardwareContext_h
  11. #pragma once
  12.  
  13. #include <stream.h>
  14. #include <assert.h>
  15. #include <AwesimeConfig.h>
  16. #include <setjmp.h>
  17.  
  18. extern long MagicStackMarker;
  19.  
  20. typedef void (*voidFuncP)();
  21.  
  22. class CpuMultiplexor;
  23. class SingleCpuMux;
  24. class MultiCpuMux;
  25. class SimulationMultiplexor;
  26. class SingleSimMux;
  27.  
  28. typedef unsigned long HardwareContextQuad;
  29.  
  30. #define HARDWARE_CONTEXT_CHECK_NONE 0
  31. #define HARDWARE_CONTEXT_CHECK_SWITCH 1
  32. #define HARDWARE_CONTEXT_CHECK_MPROTECT 2
  33.  
  34. class HardwareContext {
  35.     //
  36.     //    The following two fields are machine dependent & their order
  37.     //    should not be changed.
  38.     //
  39.     HardwareContextQuad sp;
  40.     HardwareContextQuad pc;
  41.     HardwareContextQuad out0;
  42.  
  43.     void** stackBase;    // bottom of stack
  44.     void** stackEnd;    // maximum depth of stack? (actually, a MIN value)
  45.     unsigned stackMax;    // maximum depth of stack? (actually, a MIN value)
  46.     unsigned stackSize;    // stack size in units of void*
  47.     void** stackMallocAt;
  48.  
  49.     //
  50.     // point to MagicStackMarker to check for corruption
  51.     //
  52.     long *stackCheck;
  53.     unsigned checkStackLimits;
  54.  
  55.     friend class Thread;
  56.  
  57.     friend class CpuMultiplexor;
  58.     friend class SingleCpuMux;
  59.     friend class MultiCpuMux;
  60.  
  61.     friend class SimulationMultiplexor;
  62.     friend class SingleSimMux;
  63.     
  64.     //
  65.     //    Accessed by friend classes only
  66.     //
  67.     void switchContext(HardwareContext *to);
  68.     void magicSwitchTo(HardwareContext *to);
  69.     void **getSp();
  70.     
  71.     void **mallocAt();
  72.     void buildReturnFrame(void * returnThis, voidFuncP returnAddress);
  73.     void stackOverflow();
  74.     
  75.     //
  76.     // never allocated by anything other than friend classes
  77.     //
  78.     HardwareContext(int checked, unsigned stackSize);
  79.     
  80.     void reclaimStack();
  81.  
  82. public:
  83.     HardwareContext();
  84.     
  85.     long maxStackDepth();
  86.     void checkStack(int overage = 0);
  87.     void classPrintOn(ostream& strm);
  88. };
  89.  
  90. static inline
  91. HardwareContext::HardwareContext()
  92. {
  93.     int NotReached = 0;
  94.     assert( NotReached );
  95. }
  96.  
  97. static inline ostream&
  98. operator<<(ostream& strm, HardwareContext& ob)
  99. {
  100.     ob.classPrintOn(strm);
  101.     return strm;
  102. }
  103.  
  104. static inline long
  105. HardwareContext::maxStackDepth()
  106. {
  107.     return( long(stackMax) );
  108. }
  109.  
  110. static inline void **
  111. HardwareContext::getSp()
  112. {
  113.     register int theStackPointer asm("%sp");
  114.     return( (void **) theStackPointer );
  115. }
  116.  
  117.  
  118. static inline void
  119. HardwareContext::checkStack(int overage)
  120. {
  121.     unsigned depth = stackBase - getSp() + overage;
  122.     if (stackMax < depth) {
  123.     stackMax = depth;
  124.     }
  125.     if ( stackMax >= stackSize || *stackCheck != MagicStackMarker ) {
  126.     stackOverflow();
  127.     }
  128. }
  129.  
  130. #endif    HardwareContext_h
  131.